function ProbMassDiff_Cutoff(PhatDens, densvalues_ss, cutoff, xgrid, unrate, mean_unrate)

    # density integrates to 1-ur;
    ngrid            = length(xgrid);
    densvalues_diff  = (PhatDens - densvalues_ss);
    xgrid_diff       = xgrid[2:ngrid] - xgrid[1:ngrid-1];
    probmass_diff    = densvalues_diff[2:ngrid].*xgrid_diff;
    probmass_diff[1] = probmass_diff[1]+(unrate-mean_unrate); # for mixed distribution

    out = sum(probmass_diff[xgrid[2:ngrid].<cutoff]);

    return out

end


function GiniCoef(PhatDens, xgrid, unrate)

    # density integrates to 1-ur;
    # compute probability mass function
    ngrid          = length(xgrid);
    xgrid_diff     = xgrid[2:ngrid] - xgrid[1:ngrid-1];
    probmassfcn    = PhatDens[2:ngrid].*xgrid_diff;
    probmassfcn[1] = probmassfcn[1]+unrate; # for mixed distribution

    # compute Gini coefficient
    Silag = 0;
    G     = 0;
    Si    = 1;
    for ii = 1:(ngrid-1)
        Si = sum(probmassfcn[1:ii].*xgrid[2:(1+ii)]);
        G  = G+probmassfcn[ii]*(Silag+Si);
        Silag = Si;
    end

    out = 1-G/Si;

return out

end

function mean_hat(PhatDens, xgrid, unrate)

    # density integrates to 1-ur;
    # point mass at zero does not contribute to moments
    # compute mean
    ngrid      = length(xgrid);
    xgrid_diff = xgrid[2:ngrid] - xgrid[1:ngrid-1];
    x_px       = (xgrid[2:ngrid].*PhatDens[2:ngrid]).*xgrid_diff;
    out        = sum(x_px)

return out

end

function std_hat(PhatDens, xgrid, unrate)

    # density integrates to 1-ur;
    # point mass at zero does not contribute to moments
    # compute standard deviation
    ngrid        = length(xgrid);
    xgrid_diff   = xgrid[2:ngrid] - xgrid[1:ngrid-1];
    xsq_px       = ((xgrid[2:ngrid].^2).*PhatDens[2:ngrid]).*xgrid_diff;
    out          = sqrt(sum(xsq_px) - (mean_hat(PhatDens, xgrid, unrate)^2))

    return out

end
